package com.example.papercutting.ui.fragement;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

import com.example.papercutting.R;
import com.example.papercutting.common.Item;
import com.example.papercutting.databinding.FragmentUserBinding;
import com.example.papercutting.ui.CanvasActivity;
import com.example.papercutting.ui.GalleryActivity;
import com.example.papercutting.ui.SelectionActivity;

import java.util.ArrayList;
import java.util.List;


public class UserFragment extends Fragment {

    private FragmentUserBinding binding;
    public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        binding = FragmentUserBinding.inflate(inflater, container, false);
        return binding.getRoot();
    }
    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);
        ArrayList<Item> savedWorks = CanvasActivity.getSavedWorks();

        for (Item item : savedWorks) {
            Log.d("UserFragment", item.toString()); // 使用自定义的 toString() 方法
        }
        Button works = getActivity().findViewById(R.id.user_favorite);
        works.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(getActivity(), GalleryActivity.class);
                startActivity(intent);
            }
        });
    }
    @Override
    public void onDestroyView() {
        super.onDestroyView();
        binding = null;
    }
}